"""
河南省疫情地图绘制
"""
import json
from pyecharts.charts import Map
from pyecharts.options import TitleOpts, VisualMapOpts
f = open('疫情.txt','r',encoding='utf-8')
data = f.read()
f.close()
data_dict = json.loads(data)
province_list = data_dict["areaTree"][0]["children"]
data_list = []
for province in province_list:
    if province["name"] == "河南":
        city_list = province["children"]
        for city in city_list:
            if city["name"] == "济源示范区":
                name = "济源市"
            else:
                name = city["name"] + "市"
            total = city["total"]["confirm"]
            data_list.append((name,total))
        break
print(data_list)
# 构建地图
henan_map = Map()
# 添加数据
henan_map.add("确诊人数",data_list,"河南")
# 设置全局选项
henan_map.set_global_opts(
    title_opts=TitleOpts(title="河南省疫情地图"),
    visualmap_opts=VisualMapOpts(
        is_show=True,#是否显示视觉映射组件
        is_piecewise=True,#是否分段显示
        pieces=[
            {"min":1,"max":9,"label":"1~9人","color":"#CCFFFF"},
            {"min":10,"max":99,"label":"10~99人","color":"#FFFF99"},
            {"min":100,"max":999,"label":"100~999人","color":"#FF9966"},
            {"min":1000,"max":9999,"label":"1000~9999人","color":"#FF6666"},
#             {"min":10000,"max":100000,"label":"10000~99999人","color":"#CC3333"},
#             {"min":100000,"label":"100000+人","color":"#990033"},
            ]
    ))
# 渲染地图
henan_map.render("河南省疫情地图.html")